package com.ynwa.maths.sort;

import java.util.Arrays;
import java.util.Random;

/**
 * @author gzd
 * @date 2018-10-22 上午 10:54
 * @desc 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] nums = new int[]{8, 4, 2, 7, 9, 0, 4, 5, 6, 9};
        System.out.println("初始数据: " + Arrays.toString(nums));
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (nums[j] > nums[j + 1]) {
                    int num1 = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = num1;
                }
                System.out.println("第 " + (i + j) + " 次的值: " + Arrays.toString(nums));
            }
        }
        System.out.println("数组排序值: " + Arrays.toString(nums));
    }
}
